<?php

class productPreviewComponents extends myComponents
{
    public function executeRender()
    {
        // Init entry point
        $request = sfContext::getInstance()->getRequest();
        $limit   = intval($request->getParameter('limit'));
        $offset  = 0;
        
        // Calculate offset
        if($request->hasParameter('limit') && $request->hasParameter('page'))
        {
            $offset = (($request->getParameter('page') - 1) * $request->getParameter('limit'));
        }
        
        // // Init internal properties
        $products_model  = new Product;
        $this->products  = $products_model->getLastProducts($this->getUser(), $limit, $offset);
        //$this->structure = LinkGen::getInstance(LinkGen::STRUCTURE)->link($this->getRoute()->getObject()->getId());
        $this->links     = LinkGen::getInstance(LinkGen::PRODUCT)->collectionLinks($this->products);
        $this->count     = $products_model->getLastProductsCount($this->getUser());
        $this->current   = $request->hasParameter('page') ? $request->getParameter('page') : 1;
        $this->pages     = 0;
        
        if($limit > 0)
        {
            $this->pages = round($this->count / $limit);
        }
    }
};